package com.lzh.others.basejava.Exception_12;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

/**
 * @author by lzh
 * @Classname LoggingExceptions
 * @Description 利用 java.util.logging工具记录日志
 * @Date 2022/6/28 21:43
 */
public class LoggingExceptions {
    public static void main(String[] args) {
        try {
            throw new LoggingException();
        } catch (LoggingException e) {
            System.err.println("Caught :" + e);
        }
        try {
            throw new LoggingException();
        } catch (LoggingException e) {
            System.err.println("Caught :" + e);
        }
    }
}

class LoggingException extends Exception {
    /**
     * 静态方法创建了一个String参数相关联的对象
     */
    private static final Logger logger = Logger.getLogger("LoggingException");

    public LoggingException() {
        StringWriter stringWriter = new StringWriter();
        printStackTrace(new PrintWriter(stringWriter));
        logger.severe(stringWriter.toString());
    }
}
